package com.ruoyi.api.applycopy.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.api.applycopy.domain.Applycopy;
import com.ruoyi.api.applycopy.service.IApplycopyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 抄送Controller
 *
 * @author xzshan
 * @date 2020-06-15
 */
@Controller
@RequestMapping("/api/applycopy")
public class ApplycopyController extends BaseController {
  private String prefix = "api/applycopy";

  @Autowired
  private IApplycopyService applycopyService;

  @RequiresPermissions("api:applycopy:view")
  @GetMapping()
  public String applycopy() {
    return prefix + "/applycopy";
  }

  /**
   * 查询抄送列表
   */
  @RequiresPermissions("api:applycopy:list")
  @PostMapping("/list")
  @ResponseBody
  public TableDataInfo list(Applycopy applycopy) {
    startPage();
    List<Applycopy> list = applycopyService.selectApplycopyList(applycopy);
    return getDataTable(list);
  }

  /**
   * 导出抄送列表
   */
  @RequiresPermissions("api:applycopy:export")
  @Log(title = "抄送", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  @ResponseBody
  public AjaxResult export(Applycopy applycopy) {
    List<Applycopy> list = applycopyService.selectApplycopyList(applycopy);
    ExcelUtil<Applycopy> util = new ExcelUtil<Applycopy>(Applycopy.class);
    return util.exportExcel(list, "applycopy");
  }

  /**
   * 新增抄送
   */
  @GetMapping("/add")
  public String add() {
    return prefix + "/add";
  }

  /**
   * 新增保存抄送
   */
  @RequiresPermissions("api:applycopy:add")
  @Log(title = "抄送", businessType = BusinessType.INSERT)
  @PostMapping("/add")
  @ResponseBody
  public AjaxResult addSave(Applycopy applycopy) {
    return toAjax(applycopyService.insertApplycopy(applycopy));
  }

  /**
   * 修改抄送
   */
  @GetMapping("/edit/{id}")
  public String edit(@PathVariable("id") Long id, ModelMap mmap) {
    Applycopy applycopy = applycopyService.selectApplycopyById(id);
    mmap.put("applycopy", applycopy);
    return prefix + "/edit";
  }

  /**
   * 修改保存抄送
   */
  @RequiresPermissions("api:applycopy:edit")
  @Log(title = "抄送", businessType = BusinessType.UPDATE)
  @PostMapping("/edit")
  @ResponseBody
  public AjaxResult editSave(Applycopy applycopy) {
    return toAjax(applycopyService.updateApplycopy(applycopy));
  }

  /**
   * 删除抄送
   */
  @RequiresPermissions("api:applycopy:remove")
  @Log(title = "抄送", businessType = BusinessType.DELETE)
  @PostMapping("/remove")
  @ResponseBody
  public AjaxResult remove(String ids) {
    return toAjax(applycopyService.deleteApplycopyByIds(ids));
  }
}
